<template>
	<view class="view">
		<view class="login">
			<text>找回密码</text>
		</view>
		<view style="margin-top: 10%;">
			<uni-forms ref="form" >
				<uni-forms-item label="手机号" name="">
					<uni-easyinput  v-model="user.userPhone" placeholder="请输入手机号" />
				</uni-forms-item>
				<uni-forms-item label="新密码" name="">
					<uni-easyinput  v-model="user.userPassword" placeholder="请输入密码"  type="password"/>
				</uni-forms-item>
			<uni-forms-item label="确认密码" name="">
				<uni-easyinput  v-model="password" placeholder="请输入密码"  type="password"/>
			</uni-forms-item>
				<uni-forms-item label="" name="">
					<button type="primary" @click="retrieve">确定</button>
				</uni-forms-item>
			</uni-forms>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user:{
					userPhone:"",
					userPassword:""
				},
				password:""
			}
		},
		methods: {
			retrieve(){
				if(this.user.userPassword==""||this.user.password==""){
					uni.showToast({
						title: '手机号或密码不能为空！！！',
						icon:'none'
					});
					return
				}
				if(this.user.userPassword.length<6){
					uni.showToast({
						title: '密码不能小于6位数！！！',
						icon:'none'
					});
					return
				}
				if(this.user.userPassword!=this.password){
					uni.showToast({
						title: '新密码与确认密码不相同！！！',
						icon:'none'
					});
					return
				}
				console.log("retrieve");
				uni.request({
					url: this.api.userUpdatePwd,
					method: 'PUT',
					data: this.user,
					success: res => {
						if(res.data.code==200){
							uni.navigateTo({
								url: "/pages/login/login",
								success: resf => {
									uni.showToast({
										title: res.data.message
									});
								},
								fail: () => {},
								complete: () => {}
							});
						}
						else{
							uni.showToast({
								title: res.data.message,
								icon:'error'
							});
						}
					},
					fail: () => {},
					complete: () => {}
				});
			}
			
		}
	}
</script>

<style>
	page,
	.view {
		width: 100%;
		height: 100%;
		// background-color:#D3D3D3 ;
	}
.login{
	margin-left: 10%;
	margin-top: 10%;
	font-size: 24px;
	font-weight: bold;
}
</style>
